<?php

namespace App\Admin\Controllers;

use App\Services\AiLogService;
use Slowlyo\OwlAdmin\Controllers\AdminController;
use Slowlyo\OwlAdmin\Renderers\Markdown;
use Slowlyo\OwlAdmin\Renderers\TextControl;

/**
 * 请求日志
 *
 * @property AiLogService $service
 */
class AiLogController extends AdminController
{
	protected string $serviceName = AiLogService::class;

	public function list()
	{
		$crud = $this->baseCRUD()
            ->filter($this->baseFilter()->body([
                amis()->TextControl('prompt', '提示词')->size('md')->clearable(1),
                amis()->TextControl('text_request_id', '文字请求ID')->size('md')->clearable(1),
            ]))
            ->headerToolbar([
                ...$this->baseHeaderToolBar()
            ])
			->bulkActions([])
			->columns([
				amis()->TableColumn('id', 'ID')->sortable(),
				amis()->TableColumn('app.description', '客户端'),
				amis()->TableColumn('model', '调用模型'),
				amis()->TableColumn('image_request_id', '图片请求ID'),
				amis()->TableColumn('text_request_id', '文字请求ID'),
				amis()->TableColumn('session_id', '会话ID'),
				amis()->TableColumn('created_at', admin_trans('admin.created_at'))->type('datetime')->sortable(),
				$this->rowActions([
					$this->rowShowButton('drawer', 'xl'),
				])
			]);

		return $this->baseList($crud);
	}


	public function detail()
	{
		return $this->baseDetail()->body([
			amis()->TextControl('id', 'ID')->static(),
            amis()->TextControl('app_id', '客户端ID')->static(),
            amis()->TextControl('session_id', '上下文会话ID')->static(),
            amis()->TextControl('app.description', '客户端备注')->static(),
			amis()->TextControl('prompt', '输入提示词')->static(),
            amis()->TextControl('model', '模型')->static(),
            amis()->RadiosControl('stream', '流式调用')->options([
                [
                    'label' => '是',
                    'value' => '1',
                ],
                [
                    'label' => '否',
                    'value' => '0',
                ],
            ])->disabled('1'),
			amis()->TextControl('image_token', '图片Token')->static(),
			amis()->TextControl('text_token', '文字Token')->static(),
            amis()->EditorControl('response_text', '最终结果')->language('markdown')->disabled('1'),
            amis()->EditorControl('params', '完整请求参数')->language('json')->disabled('1'),
            amis()->TextControl('image_request_id', '图片请求ID')->static(),
            amis()->EditorControl('image_response', '图片响应内容')->language('json')->disabled('1'),
            amis()->TextControl('text_request_id', '文字请求ID')->static(),
            amis()->EditorControl('text_response', '文字响应内容')->language('json')->disabled('1'),
		]);
	}
}
